<?php

declare(strict_types=1);

namespace app\example\controller;

use app\admin\BaseAdminController;
use think\facade\View;

class Tree extends BaseAdminController
{
    public function index()
    {
        View::assign('title', 'ZTree树形菜单插件/树形插件');
        View::assign('addJs', addJs(['ZTree']));
        return View::fetch();
    }

    public function view()
    {
        View::assign('title', 'treeview树状插件/树形插件');
        View::assign('addJs', addJs(['treeview']));
        return View::fetch();
    }

    public function js()
    {
        View::assign('title', 'jstree插件/树形插件');
        View::assign('addJs', addJs(['jstree']));
        return View::fetch();
    }

    public function root()
    {
        $data = <<<EOF
[
  { "id" : "demo_root_1", "text" : "Project", "children" : true, "type" : "root" },
  { "id" : "demo_root_2", "text" : "Assets", "type" : "root" },
  { "id" : "demo_root_3", "text" : "Icons", "type" : "root" },
  { "id" : "demo_root_4", "text" : "Events", "type" : "root" },
  { "id" : "demo_root_5", "text" : "Ui Kits", "type" : "root" },
  { "id" : "demo_root_6", "text" : "Forms", "type" : "root" },
  { "id" : "demo_root_7", "text" : "Chats", "type" : "root" },
  { "id" : "demo_root_8", "text" : "Pages", "type" : "root" },
  { "id" : "demo_root_9", "text" : "Tables", "type" : "root" },
  { "id" : "demo_root_10", "text" : "Documentations", "type" : "root" }
]
EOF;
        return json(json_decode($data, true));
    }

    public function children()
    {
        $data = '["Assets", { "id" : "demo_child_1", "text" : "plugins", "children" : [ { "id" : "demo_child_2", "text" : "jQuery", "type" : "file" }] }]';
        return json(json_decode($data, true));
    }
}
